package com.yanqu.road.dao.impl.activity.signindraw;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.signindraw.config.SignInDrawDrawInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class SignInDrawConfigDaoImpl extends TempDao {

    private static String getSignInDrawDrawInfoSql = "select * from `t_s_activity_anniversary_draw` where `activityId`=? ORDER BY `rewardId` ASC";
    public List<SignInDrawDrawInfo> getSignInDrawDrawInfoList(int activityId) {
        List<SignInDrawDrawInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSignInDrawDrawInfoSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SignInDrawDrawInfo data = new SignInDrawDrawInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setRewardId(rs.getInt("rewardId"));
                data.setQuality(rs.getInt("quality"));
                data.setReward(rs.getString("reward"));
                data.setTrueWeight(rs.getString("trueWeight"));
                data.setFalseWeight(rs.getString("falseWeight"));
                data.setIsNotice(rs.getInt("isNotice"));
                data.setSort(rs.getInt("sort"));
                data.setDay(rs.getInt("day"));
                data.setLimit(rs.getInt("limit"));
                data.setRewardNumLimit(rs.getInt("rewardNumLimit"));
                data.setIsMonitor(rs.getInt("isMonitor"));
                list.add(data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}
